package com.aube.rvi.net;

import android.content.Context;
import android.content.pm.PackageInfo;

import java.io.File;

public class Volley {

    /** Default on-disk cache directory. */
    public static final String DEFAULT_CACHE_DIR = "volley";

    /**
     * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
     *
     * @param context A {@link Context} to use for creating the cache dir.
     * @param stack An {@link HurlStack} to use for the network, or null for default.
     * @return A started {@link RequestQueue} instance.
     */
    public static RequestQueue newRequestQueue(Context context, HurlStack stack, int poolSize) {
        File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);

        try {
            String packageName = context.getPackageName();

            PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
        } catch (Exception e) {
            e.printStackTrace();
        }

        if (stack == null) {
            stack = new HurlStack();
        }

        RequestQueue queue = new RequestQueue(context, new DiskBasedCache(cacheDir), new BasicNetwork(stack), poolSize);
        queue.start();

        return queue;
    }

    /**
     * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
     *
     * @param context A {@link Context} to use for creating the cache dir.
     * @return A started {@link RequestQueue} instance.
     */
    public static RequestQueue newRequestQueue(Context context) {
        return newRequestQueue(context, null, RequestQueue.DEFAULT_NETWORK_THREAD_POOL_SIZE);
    }

    public static RequestQueue newRequestQueue(Context context, int size) {
        return newRequestQueue(context, null, size);
    }
    
}
